import Cookies from 'js-cookie'

export function setCookie(key, value, expires) {
	return Cookies.set(key, value, {
		expires: expires
	})
}

export function getCookie(key) {
	return Cookies.get(key)
}

export function setLocal(key, v, bool) {
	if (bool) {
		v = JSON.stringify(v)
	}
	localStorage.setItem(key, v);
}

export function getLocal(key, bool) {
	let v = localStorage.getItem(key);
	if (v) {
		v = JSON.parse(v)
	}
	return v;
}

export function removeLocal(key) {
	localStorage.removeItem(key);
}

export function clearLocal() {
	localStorage.clear();
}

export function setSession(key, v, bool) {
	if (bool) {
		v = JSON.stringify(v)
	}
	localStorage.setItem(key, v);
}

export function getSession(key, bool) {
	let v = sessionStorage.getItem(key);
	if (v) {
		v = JSON.parse(v)
	}
	return v;
}

export function removeSession(key) {
	sessionStorage.removeItem(key);
}

export function clearSession() {
	sessionStorage.clear();
}
